<template>
  <el-container>
    <el-header>
      <div>
        <img src="../assets/logo.png" @click="toWelcome" />
        <span>
          <el-button @click="toBigScreen" icon="el-icon-s-promotion"
            >点此进入大屏</el-button
          ></span
        >
      </div>

      <el-button type="info" @click="loginout" icon="el-icon-switch-button"
        >退出</el-button
      >
    </el-header>
    <el-container>
      <el-aside :width="iscollapse ? '60px' : '200px'">
        <div class="toggle-button" @click="changeCollapse">|||</div>
        <el-menu
          background-color="#333744"
          text-color="#fff"
          :unique-opened="true"
          :router="true"
          :default-active="activePath"
          :collapse-transition="false"
          :collapse="iscollapse"
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menuList"
            :key="item.id"
          >
            <template #title>
              <i :class="iconObj[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
              :index="'/' + subitem.path"
              v-for="subitem in item.children"
              :key="subitem.id"
            >
              <i class="el-icon-caret-right"></i>
              <span>{{ subitem.authName }}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      menuList: [
        {
          id: 101,
          authName: "用户管理",
          path: null,
          children: [
            {
              id: 111,
              authName: "用户列表",
              path: "users",
              children: [],
            },
          ],
        },
        {
          id: 102,
          authName: "疫情数据管理",
          path: null,
          children: [
            {
              id: 112,
              authName: "中国总体",
              path: "cncov",
              children: [],
            },
            {
              id: 113,
              authName: "中国各省市",
              path: "cncity",
              children: [],
            },
            {
              id: 118,
              authName: "世界数据",
              path: "worldcov",
              children: [],
            },
            {
              id: 114,
              authName: "美国数据",
              path: "usacov",
              children: [],
            },
            {
              id: 121,
              authName: "日本数据",
              path: "jpcov",
              children: [],
            },
            {
              id: 120,
              authName: "澳大利亚数据",
              path: "auscov",
              children: [],
            },
          ],
        },
        {
          id: 103,
          authName: "新闻和谣言",
          path: null,
          children: [
            {
              id: 115,
              authName: "新闻列表",
              path: "news",
              children: [],
            },
            {
              id: 119,
              authName: "谣言列表",
              path: "rumors",
              children: [],
            },
          ],
        },
        {
          id: 104,
          authName: "疫苗数据管理",
          path: null,
          children: [
            {
              id: 116,
              authName: "中国接种数据",
              path: "vacc",
              children: [],
            },
            {
              id: 117,
              authName: "世界接种数据",
              path: "worldvacc",
              children: [],
            },
          ],
        },
      ],
      iconObj: {
        101: "iconfont icon-user",
        102: "iconfont icon-tijikongjian",
        103: "iconfont icon-shangpin",
        104: "iconfont icon-danju",
      },
      iscollapse: false,
    };
  },
  methods: {
    loginout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    // 完成请求菜单栏数据的过程
    changeCollapse() {
      // alert('wobeidianjile ')
      this.iscollapse = !this.iscollapse;
    },
    toBigScreen() {
      this.$router.push("/bigscreen");
    },
    toWelcome() {
      this.$router.push("/welcome");
    },
  },
  created() {},
  computed: {
    activePath() {
      return this.$route.path;
    },
  },
};
</script>
<style lang="less" scoped>
.el-container {
  height: 100%;
}
.el-header {
  background-color: rgb(51 55 68);
  display: flex;
  justify-content: space-between;
  color: #fff;
  font-size: 20px;
  align-items: center;
  padding-left: 0px;
  div {
    display: flex;
    align-items: center;
    img {
      position: relative;
      height: 50px;
      //   filter: grayscale(100%) brightness(200%);
      filter: brightness(0) invert(1);
    }
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: rgb(51 55 68);
}
.el-main {
  background-color: #eaedf1;
}
.iconfont {
  margin-right: 10px;
}
.toggle-button {
  background-color: rgb(51 55 68);
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
